<?php

namespace App\Helpers;

use App\Helpers\Response\ResponseTrait;
use ErrorException;

/**
 * Trait Response 返回Response对象扩展方法
 *
 * @property \App\Helpers\Response\Response $response
 */
trait ResponseHelper
{
    public function __get($key)
    {
        $callable = [
            'response',
        ];

        if (in_array($key, $callable) && method_exists($this, $key)) {
            return $this->$key();
        }

        throw new ErrorException('Undefined property ' . get_class($this) . '::' . $key);
    }

    /**
     * @return Response 返回对象
     */
    protected function response()
    {
        return app(ResponseTrait::class);
    }
}
